<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="js/vue.js"></script>
    <script src="js/axios-0.18.0.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-form :model="ruleForm" status-icon label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="username">
            <el-input v-model="ruleForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
    </el-form>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            ruleForm: {
                username: "abc",
                password: "abc"
            }
        },
        methods: {
            submitForm() {
                console.log("submitForm()执行了");
                console.log("提交前:\n用户名:" + this.ruleForm.username + "\n" + "密码:" + this.ruleForm.password);

                //发送ajax请求
                axios.post("http://localhost:8080/login", this.ruleForm).then(resp => {
                    console.log("响应的结果为:" + resp.data.code + "\n" + resp.data.msg + "\n" + resp.data.data);
                    window.confirm("继续?");
                    //判断是否登录成功！
                    if (resp.data.code == 0) {
                        //表示登录失败,弹窗提示登录失败的原因
                        this.$message({
                            message: resp.data.msg,
                            type: 'error'
                        });
                    } else if (resp.data.code == 1) {
                        //登录成功,跳转到网站主页面
                        window.location.href = "main.html";
                    }
                });
            }
        }
    })
</script>
</body>
</html>